public class Test042704 {// 定义USB接口
    interface USB {
        void open();
        void close();
    }

    // 实现USB接口的鼠标类
    class USBMouse implements USB {
        @Override
        public void open() {
            System.out.println("USB鼠标已开启");
        }

        @Override
        public void close() {
            System.out.println("USB鼠标已关闭");
        }

        public void click() {
            System.out.println("USB鼠标点击操作");
        }
    }

    // 实现USB接口的键盘类
    class USBKeyboard implements USB {
        @Override
        public void open() {
            System.out.println("USB键盘已开启");
        }

        @Override
        public void close() {
            System.out.println("USB键盘已关闭");
        }

        public void type() {
            System.out.println("USB键盘输入操作");
        }
    }

    // 定义笔记本类
    class Notebook {
        public void run() {
            System.out.println("笔记本正在运行");
        }

        public void shutdown() {
            System.out.println("笔记本已关机");
        }

        public void useUSBDevice(USB device) {
            device.open();
            if (device instanceof USBMouse) {
                ((USBMouse) device).click();
            } else if (device instanceof USBKeyboard) {
                ((USBKeyboard) device).type();
            }
            device.close();
        }
    }

    // 测试类
    public class Main {
        public static void main(String[] args) {
            Notebook notebook = new Notebook();
            USBMouse mouse = new USBMouse();
            USBKeyboard keyboard = new USBKeyboard();

            notebook.run();
            notebook.useUSBDevice(mouse);
            notebook.useUSBDevice(keyboard);
            notebook.shutdown();
        }
    }
}
